# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python

class Recipe(recipe.Recipe):
    name = 'glib-tools'
    version = '2.50.3'
    stype = SourceType.TARBALL
    url = 'http://ftp.acc.umu.se/pub/GNOME/sources/glib/2.50/glib-%(version)s.tar.xz'
    tarball_dirname = 'glib-%(version)s'
    licenses = [License.LGPLv2Plus]
    config_sh = 'sh autogen.sh'
    configure_options = '--with-pcre=internal --disable-libmount --enable-dtrace=no '
    deps = ['libffi', 'zlib']
    can_use_configure_cache = False
    patches = ["../glib/0001-Let-user-disable-Cocoa-and-Carbon-support-on-demand.patch",
               "../glib/0002-Optionally-revert-to-the-old-pre-2.28-URI-handler-co.patch",
               "../glib/0003-Add-support-for-loading-GIO-modules-from-the-distro-.patch",
               "../glib/0004-Allow-for-a-second-distro-GIO-module-path-as-used-on.patch",
               "../glib/0005-Blacklist-the-bamf-GIO-module.patch",
               "../glib/0006-giomodule-do-not-try-to-load-modules-from-gio-module.patch",
               "../glib/0008-gdbus-codgen-Use-a-proper-shebang-in-the-generator.patch",
               "../glib/0009-Unhide-_g_io_modules_ensure_extension_points_registe.patch",
               '../glib/0015-Implementation-of-Cocoa-event-loop-integration-in-GM.patch',
               '../glib/0016-gmessages-Fix-compilation-on-Android.patch',
               '../glib/0017-GSocket-Fix-race-conditions-on-Win32-if-multiple-thr.patch',
               '../glib/0018-Check-for-RTLD_LAZY-and-others-in-configure.patch',
               '../glib/0018-Don-t-use-RTLD_DEFAULT-on-Android-for-g_module_self.patch',
               '../glib/0019-gmain-Fix-erroneous-if-condition-when-dtrace-is-disa.patch'
              ]

    def prepare(self):
        if self.config.target_platform != Platform.LINUX:
            self.configure_options += ' --disable-gtk-doc '
        elif self.config.target_platform == Platform.WINDOWS:
            self.configure_options = '--with-libiconv=gnu'
            self.append_env['CFLAGS'] = ' -DMINGW_HAS_SECURE_API=1 '
        elif self.config.target_platform in Platform.DARWIN:
            self.config_sh = 'CFLAGS="$CFLAGS -DHAVE_STRNDUP" ./configure'
